using GGPhysics;
using UnityEngine;

public class GGPSphereCollider : GGPShape
{
	public SphereShape sphere;

	public override Shape shape
	{
		get
		{
			return sphere;
		}
	}

	public override Shape CreateShapeForEngine()
	{
		SphereShape sphereShape = new SphereShape();
		Vector3 vector = base.transform.TransformPoint(sphereShape.position);
		sphereShape.position = base.transform.InverseTransformDirection(vector - base.transform.position);
		sphereShape.radius = sphere.radius;
		sphereShape.mass = sphere.mass;
		sphereShape.isTrigger = sphere.isTrigger;
		return sphereShape;
	}

	private void OnDrawGizmos()
	{
		Color color = Gizmos.color;
		Gizmos.color = Color.green;
		Vector3 center = base.transform.TransformDirection(sphere.position) + base.transform.position;
		Gizmos.DrawWireSphere(center, sphere.radius);
		Gizmos.color = color;
	}

	public void SetParamsFromMesh()
	{
		MeshRenderer component = GetComponent<MeshRenderer>();
		if (!(component == null))
		{
			Bounds bounds = component.bounds;
			sphere.position = base.transform.InverseTransformDirection(bounds.center - base.transform.position);
			sphere.radius = Mathf.Max(bounds.extents.x, bounds.extents.y, bounds.extents.z);
		}
	}
}
